package example3;

import common.ListNode;

//206. 反转链表
public class LeetCode206 {
    public static void main(String[] args) {

    }
}

//方法二：递归
class Solution206_2{
    public ListNode reverseList(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        ListNode newHead = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return newHead;
    }
}

//方法一：迭代。最快
class Solution206_1 {
    public ListNode reverseList(ListNode head) {
        ListNode curr = head;
        ListNode prev = null;
        while(curr != null){
            ListNode tempNext = curr.next;
            curr.next = prev;
            prev = curr;
            curr = tempNext;
        }
        return prev;
    }
}
